package com.longcai.piaojia.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.longcai.piaojia.R;
import com.longcai.piaojia.adapter.AppointmentDetailAdapter;
import com.longcai.piaojia.conn.AppointmentDetailGet;
import com.longcai.piaojia.widget.NoScrollListView;
import com.zcx.helper.app.AppCallBack;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/9.
 */
public class MyAppointmentDetailActivity extends BaseActivity implements View.OnClickListener {


    @BoundView(R.id.appointment_detail_sv) private ScrollView appointment_detail_sv;
    @BoundView(R.id.appointment_detail_envaluate_tv) private TextView appointment_detail_envaluate_tv;
    @BoundView(R.id.appointment_detail_state_tv) private TextView appointment_detail_state_tv;
    @BoundView(R.id.appointment_detail_name_tv) private TextView appointment_detail_name_tv;
    @BoundView(R.id.appointment_detail_order_num_tv) private TextView appointment_detail_order_num_tv;
    @BoundView(R.id.appointment_detail_ticket_num_tv) private TextView appointment_detail_ticket_num_tv;
    @BoundView(R.id.appointment_detail_pay_tv) private TextView appointment_detail_pay_tv;
    @BoundView(R.id.appointment_detail_date_tv) private TextView appointment_detail_date_tv;
    @BoundView(R.id.appointment_detail_num_tv) private TextView appointment_detail_num_tv;
    @BoundView(R.id.appointment_detail_mumber_tv) private TextView appointment_detail_mumber_tv;
    @BoundView(R.id.appointment_detail_tools_ll) private LinearLayout appointment_detail_tools_ll;
    @BoundView(R.id.appointment_detail_nslv) private NoScrollListView appointment_detail_nslv;
    private List<AppointmentDetailGet.AppointmentEntity> lists = new ArrayList<>();
    private AppointmentDetailAdapter adapter;

    private Bundle bundle;

    private AppointmentDetailGet appointmentDetailGet = new AppointmentDetailGet(new AsyCallBack<AppointmentDetailGet.AppointmentDetailEntity>() {

        @Override
        public void onSuccess(String toast, int type, AppointmentDetailGet.AppointmentDetailEntity appointmentDetailEntity) throws Exception {

            appointment_detail_sv.setVisibility(View.VISIBLE);

            lists.addAll(appointmentDetailEntity.appointmentEntityList);

            appointment_detail_envaluate_tv.setVisibility(appointmentDetailEntity.evaluate_status.equals("1") || appointmentDetailEntity.checkinfo.equals("2") ? View.GONE : View.VISIBLE);//评价状态 1是 2否

            appointment_detail_state_tv.setText(appointmentDetailEntity.checkinfo.equals("2") ? "待出票" : "已出票"); //2 待出票 3 已出票

            appointment_detail_name_tv.setText(appointmentDetailEntity.title);
            appointment_detail_order_num_tv.setText(appointmentDetailEntity.ordernumber);
            appointment_detail_ticket_num_tv.setText(appointmentDetailEntity.ticket_number);
            appointment_detail_pay_tv.setText(appointmentDetailEntity.amount);
            appointment_detail_date_tv.setText(appointmentDetailEntity.datetimes);
            appointment_detail_num_tv.setText(appointmentDetailEntity.time_tip + " " + appointmentDetailEntity.starttime + "-" + appointmentDetailEntity.endtime);
            // 是否带儿童 1 是 0 否
            appointment_detail_mumber_tv.setText(appointmentDetailEntity.name + (appointmentDetailEntity.ischild.equals("1") ? " （含儿童一名）" : " ") + appointmentDetailEntity.mobile);


            if (lists.size() > 0) {

                appointment_detail_tools_ll.setVisibility(View.VISIBLE);
            }

            adapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();

        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appointment_detail);

        setBackTrue();

        setTitleName(getString(R.string.appointment_detail_title_text));

        bundle = getIntent().getExtras();

        appointment_detail_nslv.setDivider(null);

        appointment_detail_nslv.setAdapter(adapter = new AppointmentDetailAdapter(context, lists));

        appointmentDetailGet.id = bundle.getString("id");
        appointmentDetailGet.execute(this);


        setAppCallBack(new RefreshAppointDetail());

        appointment_detail_envaluate_tv.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.appointment_detail_envaluate_tv:

                startActivity(new Intent(this, LatestEvaluateActivity.class).putExtras(bundle));

                break;

        }
    }

    public class RefreshAppointDetail implements AppCallBack {

        public void refreshDetail() {

            appointmentDetailGet.execute(context);

        }
    }

}
